import 'package:app/common/index.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

import 'index.dart';

class LoginPage extends GetView<LoginController> {
  const LoginPage({super.key});

  // 主视图
  Widget _buildView() {
    return <Widget>[
      // logo
      const ImageWidget.asset(
        AssetsImages.logoPng,
        width: 100,
        height: 100,
      ).paddingBottom(20),

      // 标题1
      TextWidget.title2(
        "Let's Sign You In",
        color: AppColors.onPrimary,
      ).paddingBottom(10),

      // 标题2
      TextWidget.body2(
        "Welcome back you've been missed!",
        color: AppColors.onPrimary,
      ).paddingBottom(55),

      // 表单
      <Widget>[
        // 用户名
        const TextWidget.body1(
          "Username or E-Mail",
          color: Color(0xff838383),
        ).paddingBottom(AppSpace.listItem).paddingTop(30),

        // 用户名输入框
        InputWidget.iconTextFilled(
          IconWidget.icon(Icons.person_outline),
          borderColor: const Color(0xffcccccc),
        ).paddingBottom(AppSpace.listItem * 2),

        // 密码
        const TextWidget.body1(
          "Password",
          color: Color(0xff838383),
        ).paddingBottom(AppSpace.listItem),

        // 密码输入框
        InputWidget.iconTextFilled(
          IconWidget.icon(Icons.lock_outline),
          borderColor: const Color(0xffcccccc),
          isObscureText: true,
        ).paddingBottom(29),

        // 登录按钮
        const ButtonWidget.primary(
          "Sign In",
          backgroundColor: Color(0xfffd8700),
          borderRadius: 18,
        )
            .tight(
              width: double.infinity,
            )
            .paddingBottom(AppSpace.listItem * 2),

        // 注册
        <Widget>[
          // 提示文字
          const TextWidget.body1(
            "Don't have an account?",
            color: Color(0xff838383),
          ).paddingRight(5),
          // 文字按钮
          ButtonWidget.text(
            "Sign Up",
            textColor: Colors.blue,
            textWeight: FontWeight.bold,
          ),
        ].toRow(
          mainAxisAlignment: MainAxisAlignment.center,
        ),
      ]
          .toColumn(
            crossAxisAlignment: CrossAxisAlignment.start,
          )
          .paddingAll(20)
          .card(
            color: Colors.white,
            radius: 35,
          ),
    ].toColumn().paddingHorizontal(15);
  }

  @override
  Widget build(BuildContext context) {
    return GetBuilder<LoginController>(
      init: LoginController(),
      id: "login",
      builder: (_) {
        return Scaffold(
          backgroundColor: const Color(0xff0274BC),
          body: SafeArea(
            child: Center(
              child: SingleChildScrollView(
                child: _buildView(),
              ),
            ),
          ),
        );
      },
    );
  }
}
